package com.partner.share.work.mq.utils;

import org.springframework.beans.BeansException;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author pengyangyan
 * @version 1.0.0
 * @date 2019年09月30日 15:26:00
 */
@ConditionalOnMissingBean(name = "springContextHolder")
@Component
public class SpringContextHolder implements ApplicationContextAware {

    private static ApplicationContext context = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }

    public static Object getBean(String beanName){
        return context.getBean(beanName);
    }

    public static <T> T getBean(String beanName,Class<T> tClass){
        return context.getBean(beanName,tClass);
    }

    public static <T> T getBean(Class<T> c){
        return context.getBean(c);
    }
}
